import { Module } from '@nestjs/common';
import { MinioService } from './minio.service';
import { MinioController } from './minio.controller';
import { ConfigService } from '@nestjs/config';
import * as Minio from 'minio';

@Module({
  controllers: [MinioController],
  providers: [
    MinioService,
    {
      provide: 'MINIO_CLIENT',
      inject: [ConfigService],
      useFactory: async (configService: ConfigService) => {
        return new Minio.Client({
          endPoint: configService.get('MINIO_END_PROINT'),
          port: Number(configService.get('MINIO_PORT')),
          useSSL: configService.get('MINIO_USE_SSL') === 'true',
          accessKey: configService.get('MINIO_ACCESS_KEY'),
          secretKey: configService.get('MINIO_SECRET_KEY'),
        });
      },
    },
  ],
  exports: [MinioService],
})
export class MinioModule {}
